<?php
class ShopKey extends logCAr
{
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	
	/* reset db */
	public function getDbConnection()
	{
		self::$db=Yii::app()->db1;
		if(self::$db instanceof CDbConnection) return self::$db;
	}


    public function relations(){
        return array(
            'shopGoods'=>array(self::BELONGS_TO,'shopGoods',array('goods_id'=>'id')),
        );
    }

    


    public function tableName()
	{
		return '{{shop_keys}}';
	}
    /* rules */
    public function rules()
    {
        return array(
            array('key_str,goods_id', 'safe', 'on'=>'search'),
        );
    }
    public function search()
    {
        $criteria=new CDbCriteria;
        $criteria->order='create_time desc';
        $criteria->compare('del_flag',0);
        $criteria->compare('goods_id',$this->goods_id);
        $criteria->compare('key_str',$this->key_str);
        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }


}